package ar.edu.itba.infovis.TPF.json;

import java.io.IOException;

import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.JsonSerializer;
import org.codehaus.jackson.map.SerializerProvider;

import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.DateTimeFormatterBuilder;

public class CustomJSONDateTimeSerializer extends JsonSerializer<DateTime>{

	@Override
	public void serialize(DateTime value, JsonGenerator jgen,
			SerializerProvider provider) throws IOException,
			JsonProcessingException {

		DateTimeFormatter dateTimeFormatter = new DateTimeFormatterBuilder()
		.appendYearOfEra(4, 4)
		.appendLiteral("-")
		.appendMonthOfYear(2)
		.appendLiteral("-")
		.appendDayOfMonth(2)
		.appendLiteral(" ")
		.appendHourOfDay(2)
		.appendLiteral(":")
		.appendMinuteOfHour(2)
		.appendLiteral(":")
		.appendSecondOfMinute(2)
		.toFormatter();
		
		jgen.writeString(dateTimeFormatter.print(value));
	}

}
